<%@ page language="java" import="java.util.*,com.advm.bean.ADInfo" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.advm.bean.PageBean"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<title>Insert title here</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="javascript" src="<%=request.getContextPath()%>/js/jquery-1.7.2.js"></script>
</head>  
</head>
<body>
<%
	int pageCount = 6;//每页显示的页数
	int rowCount = 0;//总记录数
	int crruntCount = 0;//当前的页数
	int sumPageCount = 0;//总共页数
	//获得待显示的页码
	String strPage = request.getParameter("page");
	//如果待显示的页码为空，则让当前的页数为1
	if (strPage == null)
		crruntCount = 1;
	//否则就取待显示的页码
	else
		crruntCount = Integer.parseInt(strPage);
	PageBean bean = new PageBean();
	//计算总记录数(调用数据访问类查询总记录的方法)
	rowCount = bean.sumPage();
	//计算总页数(调用数据访问类查询总页数的方法)
	sumPageCount = bean.sumPageCount(pageCount);
	//根据当前页数，每页显示的页数查询数据
	List<ADInfo> list = bean.fenYe(crruntCount, pageCount);
	request.setAttribute("info", list);
%>
	<table cellspacing="1">
		<tr bgcolor="white">
			<th width="150" height="60">编号</th>
			<th width="150" height="60">广告名称</th>
			<th width="150" height="60">标签</th>
			<th width="150" height="60">最后上传时间</th>
			<th width="150" height="60">保存路径</th>
			<th width="150" height="60">操作</th>
		</tr>
		<c:forEach var="item" items="${info}">
			<tr>
				<td width="150" height="60"><c:out value="${item.id}"></c:out>
				</td>
				<td width="150" height="60"><c:out value="${item.adName}"></c:out>
				</td>
				<td width="150" height="60"><c:out value="${item.lable}"></c:out>
				</td>
				<td width="150" height="60"><c:out value="${item.lastTime}"></c:out>
				</td>
				<td width="150" height="60"><c:out value="${item.savePath}"></c:out>
				</td>
				<td><a href="/ADVideoManager/download.do?id=${item.id}">修改</a>
					<a href="javascript:if(confirm('是否删除?')){window.location.href='/ADVideoManager/delete.do?id=${item.id}'}">【删除】</a>
					<a href="/ADVideoManager/download.do?fileName=${item.adName}">下载</a>
				</td>
			</tr>
		</c:forEach>
	</table>
	<br>
		<%
			//如果当前的页数大于1，就显示上一页；
			if (crruntCount > 1) {
		%>
		<%-- 超链接到本页面，并传递参数page的值--%>
		<a href="adinfo.do?page=<%=crruntCount - 1%>">上一页</a>
		<%
			}
		%>
		<%
			//如果当前的页数小于总页数；就显示下一页
			if (crruntCount < sumPageCount) {
		%>
		<a href="adinfo.do?page=<%=crruntCount + 1%>">下一页</a>
		<%
			}
		%>
</body>
</html>